
#SOURCES = ast.mli parser.mly lexer.mll typing.mli typing.ml mips.mli mips.ml rename.mli rename.ml compile.mli compile.ml main.ml
SOURCES = cub.mli cub.ml ast.mli parser.mly lexer.mll typing.ml compile.ml lextrace.mll trace.ml main.ml


EXEC = algony

#######################################################################
# Partie générique, ne pas modifier.
#######################################################################

# Compilateurs

CAMLC = ocamlc -annot
CAMLOPT = ocamlopt -annot
CAMLDEP = ocamldep
CAMLLEX = ocamllex
CAMLYACC = ocamlyacc

# Sources

SRC_MLL = $(filter %.mll, $(SOURCES))
SRC_MLY = $(filter %.mly, $(SOURCES))
SMLIY = $(SOURCES:.mly=.ml)
SMLIYL = $(SMLIY:.mll=.ml)
SMLYL = $(filter %.ml,$(SMLIYL))
OBJS = $(SMLYL:.ml=.cmo)
OPTOBJS = $(OBJS:.cmo=.cmx)



all: depend $(EXEC).opt

byte: depend $(EXEC).byte

#test: test.byte
#	./test.byte

#test.byte: mods.cmo parser.cmo lexer.cmo cub.cmo test.cmo
#$(CAMLC) $(CUSTOM) -o test.byte nums.cma mods.cmo parser.cmo lexer.cmo cub.cmo test.cmo

$(EXEC).byte: $(OBJS) 
	$(CAMLC) $(CUSTOM) -I +lablgtk2 -o $(EXEC).byte lablgtk.cma lablgtksourceview2.cma gtkInit.cmo nums.cma $(OBJS) 

$(EXEC).opt: $(OPTOBJS) 
	$(CAMLOPT) -I +lablgtk2 -o $(EXEC).opt lablgtk.cmxa lablgtksourceview2.cmxa gtkInit.cmx nums.cmxa $(OPTOBJS)

test: cub.cmo parser.cmo lexer.cmo typing.cmo compile.cmo test.cmo
	rm -f test.byte
	$(CAMLC) $(CUSTOM) -o test.byte nums.cma cub.cmo parser.cmo lexer.cmo typing.cmo compile.cmo test.cmo
	./test.byte


.SUFFIXES: .ml .mli .cmo .cmi .cmx .mll .mly

.ml.cmo:
	$(CAMLC) -I +lablgtk2 lablgtk.cma lablgtksourceview2.cma gtkInit.cmo -c $<

.mli.cmi:
	$(CAMLC) -c $<

.ml.cmx:
	$(CAMLOPT) -I +lablgtk2 lablgtk.cmxa lablgtksourceview2.cmxa gtkInit.cmx -c $<

.mll.cmo:
	$(CAMLLEX) $<
	$(CAMLC) -c $*.ml

.mll.cmx:
	$(CAMLLEX) $<
	$(CAMLOPT) -c $*.ml

.mly.cmo:
	$(CAMLYACC) -v $<
	$(CAMLC) -c $*.mli
	$(CAMLC) -c $*.ml

.mly.cmx:
	$(CAMLYACC) -v $< 
	$(CAMLOPT) -c $*.mli
	$(CAMLOPT) -c $*.ml

.mly.cmi:
	$(CAMLYACC) 
	$(CAMLC) -c $*.mli

.mll.ml:
	$(CAMLLEX) $<

.mly.ml:
	$(CAMLYACC) -v $<

report:
	rubber -d --inplace rapport/rapport.tex

clean:
	rm -f *.cm[iox] *~ .*~ *.o
	rm -f $(SRC_MLL:.mll=.ml) $(SRC_MLY:.mly=.ml) $(SRC_MLY:.mly=.mli)
	rm -f $(EXEC).byte
	rm -f $(EXEC).opt
	rm -f test.byte
	rm -f parser.output


depend: $(SMLIY)
	$(CAMLDEP) $(SMLIY) $(SMLIY:.mly:.mli) > depend

-include depend
